package com.fire.eyes.util;

import com.fire.eyes.model.TMitServiceDicBase;
import com.fire.eyes.service.ITMitServiceDicBaseService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wangjian_b
 * @date 2018/5/18 14:24
 * @describe 图片工具类
 */
@Component
public class ImageUtil {
    private final static String IMAGE_ADDRESS = "IMAGE_ADDRESS";

    @Autowired
    private ITMitServiceDicBaseService baseService;

    public String getAddressValue(){
        TMitServiceDicBase baseInfo = baseService.selectById(IMAGE_ADDRESS);
        String result = "";
        if(baseInfo != null){
            result = baseInfo.getBvalue();
        }
        return result;
    }

    /**
     * 图片访问地址转换
     * @param imageUrl 原图片地址
     * @return
     */
    public String imageUrlConvert (String imageUrl){
        if (StringUtils.isEmpty(imageUrl)){
            return imageUrl;
        }
        if(imageUrl.length() < 4){
        	return imageUrl;
        }
        String subStr = imageUrl.substring(0,4);
        if("http".equals(subStr)){
            return imageUrl;
        } else {
            return getAddressValue() + imageUrl;
        }
    }
}
